<?php

namespace App\Http\Controllers\Common;

use App\Http\Controllers\ClientController;
use App\Models\Common\Wechat;
use Illuminate\Support\Facades\Log;

class JsApiController extends ClientController
{
    public function index()
    {
        $all = $this->all;
        $url = $all['url'];
        try {
            $app = Wechat::officialAccount();
            $result = $app->jssdk->setUrl($url)->buildConfig([
                'updateAppMessageShareData',  // 分享给朋友/QQ
                'updateTimelineShareData',  // 分享到朋友圈/QQ空间
                'chooseWXPay',  // 微信支付
                'chooseImage', // 选择微信图片
                'uploadImage', // 上传微信图片
                'getLocalImgData', // 查看本地图片
                'getLocation', // 获取地理位置
            ]);
            return $this->setReturnJson(0, 'success', json_decode($result,true));
        } catch (\Exception $e) {
            Log::error(JsApiController::class, ['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1,'分享接口异常');
        }

    }

}
